#!/bin/bash 

function Display {
	echo "Team K's Fruit & Fibre Election Voting Prototype"
	echo "-------------------------------------------------------"
	echo ""
}

function Login {
	echo "Please enter you username."
	read username 
	echo "Please enter your password."
	read password
	
	if [ $username == Username ];then
		if [ $password == Password ]; then
			echo "Your login was successfull."
			echo""
			Menu
		else
			echo "Please try again."
		fi
	elif [ $username == Administrator ]; then
		if [ $password == TheBoss ]; then
			echo "Your login was successfull."
			echo ""
			AdminMenu
		fi
	fi
}

function Menu {
	echo "Options Menu"
	echo "--------------------------------------"
	echo ""
	OPTIONS="View-Elections Vote Nominate-Candidate"
	select opt in $OPTIONS; do
		if [ "$opt" = "View-Elections" ]; then
			echo "Here is a list of the current elections:-"
			echo""
			Elections
		elif [ "$opt" = "Vote" ]; then
			echo ""
			Vote
		elif [ "$opt" = "Nominate-Candidate" ]; then
			echo ""
			Nominate-Candidate
		fi
	done
}

function AdminMenu {
	echo "Administrator Options Menu"
	echo "----------------------------------"
	echo ""
	OPTIONS="Create-Election Delete-Election Update-Candidate-List Publish-Results"
	select opt in $OPTIONS; do
		if [ "$opt" = "Create-Election" ]; then
			echo ""
			Create-Election
		elif [ "$opt" = "Delete-Election" ]; then
			echo""
			Delete-Election
		elif [ "$opt" = "Update-Candidate-List" ]; then
			echo""
			Update-Candidate-List
		elif [ "$opt" = "Publish-Results" ]; then
			echo "The results have been published."
			quit
		fi
	done
}

function Elections {
	echo "-Student Council Election"
	echo "-Scariest Face Election"
	echo "-Best Upside Down Tree Impersonation"
	Uoptions
}

function Vote {
	echo "Here are the elections you can choose from:-"
	OPTIONS="Student-Council-Election Scariest-Face-Election Best-Upside-Down-Tree-Impersonation"
	select opt in $OPTIONS; do
		if [ "$opt" = "Student-Council-Election" ]; then
			echo""
			Candidates
		elif [ "$opt" = "Scariest-Face-Electon" ];then
			echo""
			Candidates
		elif [ "$opt" = "Best-Upside-Down-Tree-Impersonation" ]; then
			echo""
			Candidates
		fi
	done
}

function Candidates {
	echo "Here are the list of candidates you can choose from:-"
	OPTIONS="Batman Superman Chuck-Norris ? Nominate-Candidate"
	select opt in $OPTIONS; do
		if [ "$opt" = "Batman" ]; then
			echo""
			echo "Thank you for voting."
			echo "Goodbye."
			quit
		elif [ "$opt" = "Superman" ]; then
			echo ""
			echo "Thank you for voting."
			echo "Goodbye."
			quit
		elif [ "$opt" = "Chuck-Norris" ]; then
			echo ""
			echo "Thank you for voting."
			echo "Goodbye."
			quit
		elif [ "$opt" = "?" ]; then
			echo ""
			echo "/ (╯°□°）╯︵ ┻━┻ "
			echo ""
			echo "This is an invalid option. GoodBye."
			quit
		elif [ "$opt" = "Nominate-Candidate" ]; then
			echo""
			Nominate-Candidate
		fi
	done
}

function Nominate-Candidate {
	echo "Please enter the name of the candidate that you would like to nominate."
	echo ""
	read candidate
	echo "Your candidate: " $candidate " has been added to the list of candidates."
	quit
}

function Create-Election {
	echo "Please enter the name of the election you would like to create"
	echo ""
	read election
	echo "Your election: " $election " has been created."
	Aoptions
}

function Delete-Election {
	echo "Please select the election you would like to delete."
	echo ""
	OPTIONS="Student-Council-Election Scariest-Face-Election Best-Upside-Down-Tree-Impersonation"
	select opt in $OPTIONS; do
		if [ "$opt" = "Student-Council-Election" ]; then
			echo ""
			echo "The Election: Student Council Election has been removed from the list of elections."
		elif [ "$opt" = "Scariest-Face-Electon" ];then
			echo ""
			echo "The Election: Scariest Face Election has been removed from the list of elections."
		elif [ "$opt" = "Best-Upside-Down-Tree-Impersonation" ]; then
			echo ""
			echo "The Election: Best Upside Down Tree Impersonation has been removed from the list of election."
		fi
	done
	Aoptions
}

function Update-Candidate-List {
	echo "Please enter the name of the candidate you would like to add to the candidate list."
	echo ""
	read candidate
	echo "The Candidate: " $candidate " has been added to the list of candidate."
	Aoptions
} 

function Uoptions {
	echo "Do you want to do anything else?"
	OPTIONS="Yes No"
	select opt in $OPTIONS; do
		if [ "$opt" = "Yes" ]; then
			Menu
		elif [ "$opt" = "No" ]; then
			quit
		fi
	done
}

function Aoptions {
	echo "Do you want to do anything else?"
	OPTIONS="Yes No"
	select opt in $OPTIONS; do
		if [ "opt" = "Yes" ]; then
			AdminMenu
		else
			quit
		fi
	done
}
	 
function quit {
	exit
}

Display
Login

